//###############
//FILE : FileRemoveFileSession.java
//WRITER : Daniel Lowengrub, daniel_i_l, 320687098
//EXERCISE : oop ex3 2011
//DESCRIPTION:
//See below
//###############

package oop.ex3.protocol.sessions;

import oop.ex3.protocol.messages.DontContainFileMsg;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import oop.ex3.exceptions.InvalidMessageException;

/**
 * Notify a NS that we've removed a file.
 * @author daniel
 */
public class FileRemoveFileSession extends FileToNameSession {
    private String _fileName;

    /**
	 * Create a new session.
	 */
    public FileRemoveFileSession() {
        super();
    }

    /**
     * Set the name of the file that was removed.
     * @param fileName The file name.
     */
    public void setFileName(String fileName) {
        _fileName = fileName;
    }

    @Override
    protected boolean specExecuteSession(DataInputStream inputStream, DataOutputStream outputStream) throws IOException, InvalidMessageException {
        if (!initSession(inputStream, outputStream))
            return false;

        DontContainFileMsg dontContainFile = new DontContainFileMsg();
        dontContainFile.setFileName(_fileName);
        dontContainFile.send(outputStream);

        _done.receive(inputStream);

        if (!endSession(inputStream, outputStream))
            return false;
        
        return true;
    }

}
